use([
    "public/javascripts/service/trdOrderService.js",
    "public/javascripts/widget/slider/slider.js",
    "public/common/classNames.js",
    "public/javascripts/trdOrder/orderFactory.js",
    "public/javascripts/widget/dialog/dialog.js",
    "public/javascripts/widget/prompt/prompt.js"
], function (trdOrderService, SliderComponent, classNames, orderFactory, DialogComponent, PromptComponent) {
    var cx = classNames;
    var PageComponent = React.createClass({
        componentWillMount: function () {
            for (var i in orderFactory) this[i] = orderFactory[i].bind(this);
            this.selectOrderListFn = this.selectItemFn('selectOrderList');

        },
        componentDidMount: function () {
            var query = location.href.split("?")[1].split("&"),
                orderNo = orderFactory.queryString('orderNo');

            if (orderNo) {
                trdOrderService.oneOrder({orderNo: orderNo, customerType: 1}, function (res) {
                    if (res.errorCode == 0) {
                        var data = res.data, total = 0;

                        data.orderGoods.forEach(function (item) {
                            if(item.minLimit == null && item.maxLimit == null){
                                item.minLimit = item.goodsNum;
                            }
                            item.goodsType = item.goodsTypeName;
                            item.hsCode = item.goodsHSCode;
                            item.price = item.goodsPrice;
                            item.unit = item.goodsUnit;
                            total += item.amountDue;
                        });

                        this.setState({
                            purchaseName: data.customerName,
                            purchaserId: data.customerId,
                            list: data.orderGoods,
                            customerNote: data.customerNote,
                            orderNo: orderNo,
                            total: total
                        });
                    }
                }.bind(this));
            } else {
                var ids = orderFactory.queryString('ids'),
                    purchaserId = orderFactory.queryString('purchaseId'),
                    purchaseName = decodeURIComponent(orderFactory.queryString('purchaseName'));

                trdOrderService.goodList({ids: ids}, function (res) {
                    if (res.errorCode == 0) {
                        var total = 0;
                        res.data.forEach(function (item) {
                            item.goodsNum = 1;
                            item.amountDue = orderFactory.keepDecFn(item.price * item.goodsNum, 3);
                            total += item.amountDue;
                        });
                        this.setState({
                            list: res.data,
                            purchaserId: purchaserId,
                            purchaseName: purchaseName,
                            total: total
                        });
                    }
                }.bind(this));
            }
        },
        receiveMsg: function (data) {

        },
        getInitialState: function () {
            var state = {
                selectOrderList: {}
            };
            orderFactory.extend(state, this.props);
            return state;
        },
        render: function () {
            var data = this.state.data, list = new Array(30),
                selectOrderList = this.state.selectOrderList,
                list = this.state.list || [],
                customerNote = this.state.customerNote,
                component = this;
            return ~init;
        }
    });
    if (typeof ReactDOM != "undefined") {
        ReactDOM.render(<PageComponent data={storage}/>, document.getElementById('container'));
    }
    module.exports = PageComponent;
});